# Contributor: Justin Berthault <justin.berthault@zaclys.net>
# Maintainer: Justin Berthault <justin.berthault@zaclys.net>
pkgname=writefreely
pkgver=0.13.1
pkgrel=22
pkgdesc="Federated blogging from write.as"
url="https://writefreely.org"
arch="all !riscv64" # riscv64 fails to build
license="AGPL-3.0-or-later"
pkgusers="$pkgname"
pkggroups="$pkgname"
makedepends="go go-bindata sqlite-dev npm"
install="$pkgname.pre-install"
source="$pkgname-$pkgver.tar.gz::https://github.com/writefreely/writefreely/archive/v$pkgver.tar.gz
	package.json
	package-lock.json
	https://dev.alpinelinux.org/~psykose/writefreely-openssl3.patch
	config.ini
	"
options="!check net"

export GOFLAGS="$GOFLAGS -modcacherw"
export GOCACHE="${GOCACHE:-"$srcdir/go-cache"}"
export GOTMPDIR="${GOTMPDIR:-"$srcdir"}"
export GOMODCACHE="${GOMODCACHE:-"$srcdir/go"}"

prepare() {
	default_prepare

	cp "$srcdir"/package*.json .
	npm clean-install

	(
		cd cmd/writefreely
		go mod download -x
	)

	(
		cd prose
		npm clean-install --frozen-lockfile
	)
}

build() {
	PATH="$PWD/node_modules/.bin:$PATH" make -C less

	(
		cd prose
		npm run-script build
	)

	make assets

	cd cmd/writefreely
	go build -v -tags=sqlite,libsqlite3
}

check() {
	make test
}

package() {
	install -d -o $pkgname -g $pkgname "$pkgdir"/var/lib/$pkgname
	install -d -o $pkgname -g $pkgname "$pkgdir"/var/lib/$pkgname/keys
	install -d -o $pkgname -g $pkgname "$pkgdir"/var/lib/$pkgname/data

	install -dm755 "$pkgdir"/usr/share/$pkgname/pages
	install -dm755 "$pkgdir"/usr/share/$pkgname/static
	install -dm755 "$pkgdir"/usr/share/$pkgname/templates

	install -Dm644 "$srcdir"/config.ini "$pkgdir"/etc/writefreely/config.ini

	install -Dm755 "$builddir"/cmd/$pkgname/$pkgname "$pkgdir"/usr/bin/$pkgname
	cp -r "$builddir"/pages/* "$pkgdir"/usr/share/writefreely/pages
	cp -r "$builddir"/static/* "$pkgdir"/usr/share/writefreely/static
	cp -r "$builddir"/templates/* "$pkgdir"/usr/share/writefreely/templates
}

sha512sums="
59106f78d1040c30c9ef5ebc6240e4f8f4a2ef4cbbb5531eabd3a040c341e27059dd7242227e288e84b8f9f953b5aa2600988cb1de45d404727f6a9d1e027db2  writefreely-0.13.1.tar.gz
56aa3017b34a11b77a318772d2e34645a017e2ac66e75205dac31d4d6f2c7da48a6ced7ec8050babe258c7719151b79c9bb668f1fa6243f09fd1268d4eefc602  package.json
e845c1edfd442bcb6f3d9180acb742502274cd9eb72a4506d9199d2b9aadf03a6f146c4b61d2257649404f16708a0b7812c382f3f22c2299688b09bb25c810b4  package-lock.json
2d0d3b513eb4847b0b77738e158c28a37b19d304990ef31a8c8452d6064c008cb49a7538b35b3c0476c3312c6673ca3997ca87de71ea299333a8eab540d2edf6  writefreely-openssl3.patch
27685562af68e5c03850cf346e95f87657dfceffc396441ca3315ca2065ccd4ea86dbd831b0c3f1dce99de4a6317eaf495ce979d5e98c3feeebbd0fbc793fa30  config.ini
"
